﻿using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Data;
namespace WPFExcelReport
{
    public partial class PRJTMP : DocumentBase
    {
        public   ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        public DataTable TBPRG
        {
            get
            {
                return app.TBPRG;
            }
            set
            {
                app.TBPRG = value;
            }
        }
        public DataTable TBUR
        {
            get
            {
                return app.TBUR;
            }
            set
            {
                app.TBUR = value;
            }
        }

        #region ==IsChgZA===========
        public static readonly DependencyProperty IsChgZAProperty = DependencyProperty.Register("IsChgZA",
            typeof(bool), typeof(PRJVK),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsChgZAChanged));
        public bool IsChgZA
        {
            get
            {
                return (bool)GetValue(IsChgZAProperty);
            }
            set
            {
                SetValue(IsChgZAProperty, value);
            }
        }
        private static void OnIsChgZAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as PRJVK;
            if (src != null)
            {
                src.IsChgZA = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsCanPay===========
        public static readonly DependencyProperty IsCanPayProperty = DependencyProperty.Register("IsCanPay",
            typeof(bool), typeof(PRJVK),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCanPayChanged));
        public bool IsCanPay
        {
            get
            {
                return (bool)GetValue(IsCanPayProperty);
            }
            set
            {
                SetValue(IsCanPayProperty, value);
            }
        }
        private static void OnIsCanPayChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as PRJVK;
            if (src != null)
            {
                src.IsCanPay = (bool)e.NewValue;
            }
        }
        #endregion
         
        #region ==VKAUF===========
        public static readonly DependencyProperty VKAUFProperty = DependencyProperty.Register("VKAUF",
        typeof(string), typeof(PRJVK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKAUFChanged));
        public string VKAUF
        {
            get
            {
                return (string)GetValue(VKAUFProperty);
            }
            set
            {
                SetValue(VKAUFProperty, value);
            }
        }
        private static void OnVKAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as PRJVK;
            if (src != null)
            {
                src.VKAUF = (string)e.NewValue;
            }
        }
        #endregion
        public override void OnMasterChg(DataRow row)
        {
             
            base.OnMasterChg(row);
        }
         
        MetroViewModel MV;
        public PRJTMP()
        {
            
        } 
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (IsLoaded)
                return;
            if (MV == null)
                MV = DataContext as MetroViewModel;
            base.Window_Loaded(sender, e);
        }
        public override void OnNWFIDChg(string value)
        {
            base.OnNWFIDChg(value);
            if (MV == null)
                return;
            MV.NWFID = value;
        }
        public override void NewWFChg(bool value)
        {
            base.NewWFChg(value);
            if (MV == null)
                return;
            MV.IsNewWF = value;
        }

        public override void OnWorkflowIDChange(string wfid)
        {
            base.OnWorkflowIDChange(wfid); 
        }
        public override void SetUpUserRight()
        {
            base.SetUpUserRight();
            Type mom = this.GetType();
            if (mom == null)
                return;
            string filter = "USERID='" + app.User + "' AND PROG='" + mom.Name.PadRight(80) + "'";
            DataRow[] rows = TBUR.Select(filter);
            foreach (DataRow row in rows)
            {
                string contol = row["CONTROLS"].ToString();//属性 
                string PROCESS = row["PROCESS"].ToString();//控制值
                string txt = row["P0"].ToString();//文本值 
                bool blControl = true;
                if (PROCESS.Trim() == "N")
                {
                    blControl = false; ;
                }
                if (PROCESS.Trim() == "Y")
                {
                    blControl = true; ;
                }
                switch (contol.Trim())
                {
                    case "DEL":
                        IsCanDelete = blControl;
                        break;
                    case "NEW":
                        IsCanNew = blControl;
                        break;
                    case "CHG":
                        IsCanChg = blControl;
                        break;
                    case "COPY":
                        IsCanCopy = blControl;
                        break;
                    case "MS":
                        ScopeManage = txt;
                        break;
                    case "CHGZA":
                        IsChgZA = blControl;
                        break;
                }
            }
        }
    }
}
